import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { DailyInfo } from "../../model/DailyInfo";
import { DailyRule } from "../../rules/DailyRule";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { Language } from "../../../../extend/language/Language";
import { SystemSetter } from "../system/SystemSetter";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { WalkthroughTip } from "./WalkthroughTip";
import { GButton } from "../../../../com/mui/controls/GButton";
import { DataEvent } from "../../events/DataEvent";
type int = number;
//class WalkthroughItemRenderer
    
    export  class WalkthroughItemRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this._starArray = [];
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            this._dailyInfo = arg1 as DailyInfo;
            this._nameTxt.text = this._dailyInfo.subName + "：";
            this.updateRecomment(this._dailyInfo.wtRecommend);
            if (this._dailyInfo.type == DailyRule.Screen) 
            {
                Dispatcher.addEventListener(EventName.SysSettingSuccess, this.SysSettingSuccessHandler);
            }
            if (this._dailyInfo.button != 2) 
            {
                if (this._dailyInfo.flyFoot) 
                {
                    this._flyBtn.visible = true;
                }
                else 
                {
                    this._flyBtn.visible = false;
                }
                this._goBtn.visible = true;
                this._detailBtn.visible = false;
            }
            else 
            {
                this._detailBtn.label = Language.getString(51041);
                this._detailBtn.visible = true;
                this._goBtn.visible = false;
                this._flyBtn.visible = false;
                if (this._dailyInfo.type == DailyRule.BrowsetCacheSet || this._dailyInfo.type == DailyRule.LocalCacheSet || this._dailyInfo.type == DailyRule.SetShowNum) 
                {
                    this._detailBtn.label = Language.getString(51042);
                }
                else if (this._dailyInfo.type == DailyRule.Screen) 
                {
                    if (SystemSetter.currentSetter.hideNearPlayerPet) 
                    {
                        this._detailBtn.label = Language.getString(51043);
                    }
                    else 
                    {
                        this._detailBtn.label = Language.getString(51044);
                    }
                }
                this._detailBtn.drawNow();
            }
            this._tipSprite.dailyInfo = this._dailyInfo;
            return;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            this._nameTxt = ObjCreate.createGTextField("", 0, 3, 130, 20, this);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._recommendTxt = ObjCreate.createGTextField(Language.getString(51045), 140, 3, 35, 20, this);
            var loc2=1;
            while (loc2 <= 5) 
            {
                loc1 = ObjCreate.createBg(175, 3, 16, 14, this, ImagesConst.star2);
                loc1.x = (loc2 - 1) * 16 + 175;
                this._starArray.push(loc1);
                ++loc2;
            }
            this._detailBtn = ObjCreate.createGButton(Language.getString(51041), 265, 0, 70, 24, this);
            this._detailBtn.name = "detail";
            this._goBtn = ObjCreate.createGButton(Language.getString(51046), 265, 0, 60, 24, this);
            this._goBtn.name = "go";
            this._flyBtn = ObjCreate.createGButton(Language.getString(51047), 330, 0, 60, 24, this);
            this._flyBtn.name = "fly";
            this._goBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHander);
            this._flyBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHander);
            this._detailBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHander);
            this._detailBtn.toolTipData = HTMLUtil.addColor(Language.getString(51048), "#ffffff");
            this._goBtn.toolTipData = HTMLUtil.addColor(Language.getString(51049), "#ffffff");
            this._flyBtn.toolTipData = HTMLUtil.addColor(Language.getString(51050), "#ffffff");
            this._detailBtn.drawNow();
            this._goBtn.drawNow();
            this._flyBtn.drawNow();
            this._tipSprite = new WalkthroughTip();
            this._tipSprite.y = 3;
            this.addChild(this._tipSprite);
            return;
        }

        /* internal  */updateRecomment(arg1: int): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < 5) 
            {
                loc1 = this._starArray[loc2];
                if (loc2 < arg1) 
                {
                    loc1.visible = true;
                }
                else 
                {
                    loc1.visible = false;
                }
                ++loc2;
            }
            return;
        }

        /* internal  */onBtnClickHander(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=(arg1.target as GButton).name;
            if (this._dailyInfo) 
            {
                if (loc1 == "go" || loc1 == "detail") 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.DailyActiveGoTo, this._dailyInfo));
                }
                else if (loc1 == "fly") 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.DailyActiveFlyTo, this._dailyInfo));
                }
            }
            return;
        }

        /* internal  */SysSettingSuccessHandler(arg1: DataEvent): void
        {
            if (SystemSetter.currentSetter.hideNearPlayerPet) 
            {
                this._detailBtn.label = Language.getString(51043);
            }
            else 
            {
                this._detailBtn.label = Language.getString(51044);
            }
            this._detailBtn.drawNow();
            return;
        }

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_recommendTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_goBtn: GButton;

        /* internal */ /* var */_flyBtn: GButton;

        /* internal */ /* var */_detailBtn: GButton;

        /* internal */ /* var */_tipSprite: WalkthroughTip;

        /* internal */ /* var */_starArray: Array<any>;

        /* internal */ /* var */_dailyInfo: DailyInfo;
    }
